<!DOCTYPE html><html class="theme-next gemini use-motion" lang=zh-CN><head><meta name=generator content="Hexo 3.8.0"><meta charset=UTF-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width, initial-scale=1, maximum-scale=2"><meta name=theme-color content=#222><link rel=stylesheet href="/note/lib/font-awesome/css/font-awesome.min.css?v=4.6.2"><link rel=stylesheet href="/note/css/main.css?v=7.1.1"><link rel=apple-touch-icon sizes=180x180 href="/note/images/apple-touch-icon-next.png?v=7.1.1"><link rel=icon type=image/png sizes=32x32 href="/note/images/leaf-32px.png?v=7.1.1"><link rel=icon type=image/png sizes=16x16 href="/note/images/leaf-16px.png?v=7.1.1"><link rel=mask-icon href="/note/images/logo.svg?v=7.1.1" color=#222><script id=hexo.configurations>
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/note/',
    scheme: 'Gemini',
    version: '7.1.1',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: true,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script><meta name=description content="配置信息12$ git config --global user.name &quot;Your Name&quot;$ git config --global user.email &quot;email@example.com&quot; 注意：–global参数，用了这个参数，表示你这台机器上所有的Git仓库都会使用这个配置。"><meta name=keywords content=Git><meta property=og:type content=article><meta property=og:title content=Git常用命令><meta property=og:url content=http://https://fyypll.gitee.io/note/posts/caff8000.html><meta property=og:site_name content=枫林幻境><meta property=og:description content="配置信息12$ git config --global user.name &quot;Your Name&quot;$ git config --global user.email &quot;email@example.com&quot; 注意：–global参数，用了这个参数，表示你这台机器上所有的Git仓库都会使用这个配置。"><meta property=og:locale content=zh-CN><meta property=og:updated_time content=2019-11-16T13:22:27.441Z><meta name=twitter:card content=summary><meta name=twitter:title content=Git常用命令><meta name=twitter:description content="配置信息12$ git config --global user.name &quot;Your Name&quot;$ git config --global user.email &quot;email@example.com&quot; 注意：–global参数，用了这个参数，表示你这台机器上所有的Git仓库都会使用这个配置。"><link rel=alternate href=/note/atom.xml title=枫林幻境 type=application/atom+xml><link rel=canonical href=http://https://fyypll.gitee.io/note/posts/caff8000><script id=page.configurations>
  CONFIG.page = {
    sidebar: "",
  };
</script><title>Git常用命令 | 枫林幻境</title><noscript><style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style></noscript></head><body itemscope itemtype=http://schema.org/WebPage lang=zh-CN><div class="container sidebar-position-left page-post-detail"><div class=headband></div><header id=header class=header itemscope itemtype=http://schema.org/WPHeader><div class=header-inner><div class=site-brand-wrapper><div class=site-meta><div class=custom-logo-site-title><a href="/note/" class=brand rel=start><span class=logo-line-before><i></i></span> <span class=site-title>枫林幻境</span> <span class=logo-line-after><i></i></span></a></div><p class=site-subtitle>人生若只如初见</p></div><div class=site-nav-toggle><button aria-label=切换导航栏><span class=btn-bar></span> <span class=btn-bar></span> <span class=btn-bar></span></button></div></div><nav class=site-nav><ul id=menu class=menu><li class="menu-item menu-item-home"><a href="/note/" rel=section><i class="menu-item-icon fa fa-fw fa-home"></i><br>首页</a></li><li class="menu-item menu-item-tags"><a href="/note/tags/" rel=section><i class="menu-item-icon fa fa-fw fa-tags"></i><br>标签</a></li><li class="menu-item menu-item-categories"><a href="/note/categories/" rel=section><i class="menu-item-icon fa fa-fw fa-th"></i><br>分类</a></li><li class="menu-item menu-item-archives"><a href="/note/archives/" rel=section><i class="menu-item-icon fa fa-fw fa-archive"></i><br>归档</a></li><li class="menu-item menu-item-about"><a href="/note/about/" rel=section><i class="menu-item-icon fa fa-fw fa-user"></i><br>关于</a></li><li class="menu-item menu-item-search"><a href=javascript:; class=popup-trigger><i class="menu-item-icon fa fa-search fa-fw"></i><br>搜索</a></li></ul><div class=site-search><div class="popup search-popup local-search-popup"><div class="local-search-header clearfix"><span class=search-icon><i class="fa fa-search"></i></span> <span class=popup-btn-close><i class="fa fa-times-circle"></i></span><div class=local-search-input-wrapper><input autocomplete=off placeholder=搜索... spellcheck=false type=text id=local-search-input></div></div><div id=local-search-result></div></div></div></nav></div></header><main id=main class=main><div class=main-inner><div class=content-wrap><div id=content class=content><div id=posts class=posts-expand><article class="post post-type-normal" itemscope itemtype=http://schema.org/Article><div class=post-block><link itemprop=mainEntityOfPage href=http://https://fyypll.gitee.io/note/note/posts/caff8000.html><span hidden itemprop=author itemscope itemtype=http://schema.org/Person><meta itemprop=name content=枫雨><meta itemprop=description content=时光再美，怎如初见><meta itemprop=image content=/note/images/author.jpg></span> <span hidden itemprop=publisher itemscope itemtype=http://schema.org/Organization><meta itemprop=name content=枫林幻境></span><header class=post-header><h1 class=post-title itemprop="name headline">Git常用命令</h1><div class=post-meta><span class=post-time><span class=post-meta-item-icon><i class="fa fa-calendar-o"></i></span> <span class=post-meta-item-text>发表于</span><time title="创建时间：2019-01-29 19:34:27" itemprop="dateCreated datePublished" datetime=2019-01-29T19:34:27+08:00>2019-01-29</time><span class=post-meta-divider>|</span> <span class=post-meta-item-icon><i class="fa fa-calendar-check-o"></i></span> <span class=post-meta-item-text>更新于</span><time title="修改时间：2019-11-16 21:22:27" itemprop=dateModified datetime=2019-11-16T21:22:27+08:00>2019-11-16</time></span> <span class=post-category><span class=post-meta-divider>|</span> <span class=post-meta-item-icon><i class="fa fa-folder-o"></i></span> <span class=post-meta-item-text>分类于</span> <span itemprop=about itemscope itemtype=http://schema.org/Thing><a href="/note/categories/Git/" itemprop=url rel=index><span itemprop=name>Git</span></a></span> ， <span itemprop=about itemscope itemtype=http://schema.org/Thing><a href="/note/categories/Git/Shell/" itemprop=url rel=index><span itemprop=name>Shell</span></a></span></span> <span class=post-comments-count><span class=post-meta-divider>|</span> <span class=post-meta-item-icon><i class="fa fa-comment-o"></i></span> <span class=post-meta-item-text>评论数：</span> <a href=/note/posts/caff8000.html#comments itemprop=discussionUrl><span class="post-comments-count valine-comment-count" data-xid=/note/posts/caff8000.html itemprop=commentCount></span></a></span> <span class=post-meta-divider>|</span> <span class=post-meta-item-icon><i class="fa fa-eye"></i> 阅读次数： <span class=busuanzi-value id=busuanzi_value_page_pv></span></span><div class=post-symbolscount><span class=post-meta-item-icon><i class="fa fa-file-word-o"></i></span> <span class=post-meta-item-text>本文字数：</span> <span title=本文字数>4.4k</span> <span class=post-meta-divider>|</span> <span class=post-meta-item-icon><i class="fa fa-clock-o"></i></span> <span class=post-meta-item-text>阅读时长 &asymp;</span> <span title=阅读时长>4 分钟</span></div></div></header><div class=post-body itemprop=articleBody><h3 id=配置信息><a href=#配置信息 class=headerlink title=配置信息></a>配置信息</h3><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br></pre></td><td class=code><pre><span class=line>$ git config --global user.name <span class=string>"Your Name"</span></span><br><span class=line>$ git config --global user.email <span class=string>"email@example.com"</span></span><br></pre></td></tr></table></figure><p>注意：–global参数，用了这个参数，表示你这台机器上所有的Git仓库都会使用这个配置。</p><a id=more></a><h3 id=创建仓库><a href=#创建仓库 class=headerlink title=创建仓库></a>创建仓库</h3><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br></pre></td><td class=code><pre><span class=line>$ git init</span><br></pre></td></tr></table></figure><h3 id=添加文件到仓库><a href=#添加文件到仓库 class=headerlink title=添加文件到仓库></a>添加文件到仓库</h3><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br></pre></td><td class=code><pre><span class=line>$ git add &lt;file&gt;</span><br><span class=line>$ git commit -m &lt;message&gt;</span><br></pre></td></tr></table></figure><p>例如提交<code>readme.txt</code>文件可以这样做：</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br></pre></td><td class=code><pre><span class=line>$ git add readme.txt</span><br><span class=line>$ git commit -m <span class=string>"第一次提交"</span></span><br></pre></td></tr></table></figure><p>注意：<code>git add</code> 可反复多次使用，添加多个文件，到时候可以直接<code>git commit</code>一次性提交</p><h3 id=查看仓库当前状态><a href=#查看仓库当前状态 class=headerlink title=查看仓库当前状态></a>查看仓库当前状态</h3><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br></pre></td><td class=code><pre><span class=line>$ git status</span><br></pre></td></tr></table></figure><h3 id=查看文件的改动情况><a href=#查看文件的改动情况 class=headerlink title=查看文件的改动情况></a>查看文件的改动情况</h3><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br><span class=line>3</span><br></pre></td><td class=code><pre><span class=line>$ git diff 是只比较比较工作区和暂存区（最后一次add）的区别</span><br><span class=line>$ git diff --cached 是只比较暂存区和版本库的区别</span><br><span class=line>$ git diff HEAD -- filename 是只比较工作区和版本库（最后一次commit）的区别</span><br></pre></td></tr></table></figure><p>简单理解：</p><p>工作区：存文件的这个仓库(目录)</p><p>暂存区：<code>git add</code>添加到的区域</p><p>版本库：<code>git commit</code>提交到的区域</p><p>流程：</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br></pre></td><td class=code><pre><span class=line>工作区修改-&gt;git add 添加记录到暂存区-&gt;git commit 提交到版本库</span><br></pre></td></tr></table></figure><h3 id=查看改动历史记录><a href=#查看改动历史记录 class=headerlink title=查看改动历史记录></a>查看改动历史记录</h3><p><code>git log</code>命令</p><p>示例：</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br><span class=line>3</span><br><span class=line>4</span><br><span class=line>5</span><br><span class=line>6</span><br><span class=line>7</span><br><span class=line>8</span><br><span class=line>9</span><br><span class=line>10</span><br><span class=line>11</span><br><span class=line>12</span><br><span class=line>13</span><br><span class=line>14</span><br><span class=line>15</span><br><span class=line>16</span><br><span class=line>17</span><br><span class=line>18</span><br><span class=line>19</span><br><span class=line>20</span><br><span class=line>21</span><br><span class=line>22</span><br><span class=line>23</span><br><span class=line>24</span><br><span class=line>25</span><br><span class=line>26</span><br><span class=line>27</span><br><span class=line>28</span><br><span class=line>29</span><br><span class=line>30</span><br><span class=line>31</span><br><span class=line>32</span><br><span class=line>33</span><br><span class=line>34</span><br><span class=line>35</span><br><span class=line>36</span><br></pre></td><td class=code><pre><span class=line>$ git <span class=built_in>log</span></span><br><span class=line>commit 1cc9ea2abcc2a1ab7e962e2f399f7cd704ec7d74 (HEAD -&gt; master)</span><br><span class=line>Author: fyypll fyypll@163.com</span><br><span class=line>Date:   Mon Jan 28 02:24:51 2019 +0800</span><br><span class=line></span><br><span class=line>修改了<span class=built_in>test</span>文件的编码为utf-8</span><br><span class=line></span><br><span class=line>commit b94e156795bf0001e0840500905f29b4683b5c07</span><br><span class=line>Author: fyypll fyypll@163.com</span><br><span class=line>Date:   Mon Jan 28 02:17:07 2019 +0800</span><br><span class=line></span><br><span class=line>修改了readme文件并且添加了<span class=built_in>test</span>文件</span><br><span class=line></span><br><span class=line>commit b50eaa62f6281b46c166ccdacd7ef43b8031e0e9</span><br><span class=line>Author: fyypll fyypll@163.com</span><br><span class=line>Date:   Mon Jan 28 01:55:26 2019 +0800</span><br><span class=line></span><br><span class=line>第四次修改，增加了学习Git的说明</span><br><span class=line></span><br><span class=line>commit 03b94083fcecd5c715108620358e1d6ea551193d</span><br><span class=line>Author: fyypll fyypll@163.com</span><br><span class=line>Date:   Mon Jan 28 01:50:06 2019 +0800</span><br><span class=line></span><br><span class=line>第三次修改</span><br><span class=line></span><br><span class=line>commit 38448a2844d3c00ec37a25044a44d8aff4a8f24b</span><br><span class=line>Author: fyypll fyypll@163.com</span><br><span class=line>Date:   Mon Jan 28 01:43:41 2019 +0800</span><br><span class=line></span><br><span class=line>添加了分割线</span><br><span class=line></span><br><span class=line>commit 60e0866f4d780bf735d3854df8243f219eb42050</span><br><span class=line>Author: fyypll fyypll@163.com</span><br><span class=line>Date:   Mon Jan 28 01:37:24 2019 +0800</span><br><span class=line></span><br><span class=line>第一次提交</span><br></pre></td></tr></table></figure><p>嫌输出信息太多？可以加上<code>--pretty=oneline</code>参数，显示简略的信息</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br><span class=line>3</span><br><span class=line>4</span><br><span class=line>5</span><br><span class=line>6</span><br><span class=line>7</span><br></pre></td><td class=code><pre><span class=line>$ git <span class=built_in>log</span> --pretty=oneline</span><br><span class=line>1cc9ea2abcc2a1ab7e962e2f399f7cd704ec7d74 (HEAD -&gt; master) 修改了<span class=built_in>test</span>文件的编码为utf-8</span><br><span class=line>b94e156795bf0001e0840500905f29b4683b5c07 修改了readme文件并且添加了<span class=built_in>test</span>文件</span><br><span class=line>b50eaa62f6281b46c166ccdacd7ef43b8031e0e9 第四次修改，增加了学习Git的说明</span><br><span class=line>03b94083fcecd5c715108620358e1d6ea551193d 第三次修改</span><br><span class=line>38448a2844d3c00ec37a25044a44d8aff4a8f24b 添加了分割线</span><br><span class=line>60e0866f4d780bf735d3854df8243f219eb42050 第一次提交</span><br></pre></td></tr></table></figure><p>显示的<code>1cc9ea2abcc2a1ab7e962e2f399f7cd704ec7d74</code>这一类东西是<code>commit id</code>，每次提交都会有一个</p><h3 id=版本回退><a href=#版本回退 class=headerlink title=版本回退></a>版本回退</h3><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br><span class=line>3</span><br><span class=line>4</span><br><span class=line>5</span><br><span class=line>6</span><br><span class=line>7</span><br><span class=line>8</span><br></pre></td><td class=code><pre><span class=line>退回往上第n个版本</span><br><span class=line>$ git reset --hard HEAD~n</span><br><span class=line>退回指定commit id的版本</span><br><span class=line>$ git reset --hard &lt;commit id&gt;</span><br><span class=line>查看提交日志</span><br><span class=line>$ git <span class=built_in>log</span></span><br><span class=line>查看所有运行的命令</span><br><span class=line>$ git refolg</span><br></pre></td></tr></table></figure><p>退回以前的版本有两个方法</p><p>方法一：</p><p>比如退回上一个版本就这样</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br></pre></td><td class=code><pre><span class=line>$ git reset --hard HEAD^</span><br></pre></td></tr></table></figure><p>在Git中，用<code>HEAD</code>表示当前版本，上一个版本就是<code>HEAD^</code>，上上一个版本就是<code>HEAD^^</code>，当然往上100个版本写100个<code>^</code>比较容易数不过来，所以写成<code>HEAD~100</code></p><p>方法二：</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br></pre></td><td class=code><pre><span class=line>$ git reset --hard b94e15</span><br></pre></td></tr></table></figure><p>这里，<code>b94e15</code>是<code>修改了readme文件并且添加了test文件</code> 这一次提交的<code>commit id</code>，是的，我们只需要输入<code>commit id</code>前面的一部分，Git就会自动找到它。</p><p>从新版本退回到旧版本并且<strong>已经关闭了命令行窗口</strong>，那么再次通过<code>git log</code>已经无法看到原来最新的版本了，情况如下：</p><p>退回旧版本前：</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br><span class=line>3</span><br><span class=line>4</span><br><span class=line>5</span><br><span class=line>6</span><br><span class=line>7</span><br></pre></td><td class=code><pre><span class=line>$ git <span class=built_in>log</span> --pretty=oneline</span><br><span class=line>1cc9ea2abcc2a1ab7e962e2f399f7cd704ec7d74 (HEAD -&gt; master) 修改了<span class=built_in>test</span>文件的编码为utf-8</span><br><span class=line>b94e156795bf0001e0840500905f29b4683b5c07 修改了readme文件并且添加了<span class=built_in>test</span>文件</span><br><span class=line>b50eaa62f6281b46c166ccdacd7ef43b8031e0e9 第四次修改，增加了学习Git的说明</span><br><span class=line>03b94083fcecd5c715108620358e1d6ea551193d 第三次修改</span><br><span class=line>38448a2844d3c00ec37a25044a44d8aff4a8f24b 添加了分割线</span><br><span class=line>60e0866f4d780bf735d3854df8243f219eb42050 第一次提交</span><br></pre></td></tr></table></figure><p>执行了回退命令且手贱关闭了命令行窗口，然后重开命令行输入<code>git log --pretty=oneline</code>查看得结果</p><p>退回旧版本后：</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br><span class=line>3</span><br><span class=line>4</span><br><span class=line>5</span><br><span class=line>6</span><br></pre></td><td class=code><pre><span class=line>$ git <span class=built_in>log</span> --pretty=oneline</span><br><span class=line>b94e156795bf0001e0840500905f29b4683b5c07 (HEAD -&gt; master) 修改了readme文件并且添加了<span class=built_in>test</span>文件</span><br><span class=line>b50eaa62f6281b46c166ccdacd7ef43b8031e0e9 第四次修改，增加了学习Git的说明</span><br><span class=line>03b94083fcecd5c715108620358e1d6ea551193d 第三次修改</span><br><span class=line>38448a2844d3c00ec37a25044a44d8aff4a8f24b 添加了分割线</span><br><span class=line>60e0866f4d780bf735d3854df8243f219eb42050 第一次提交</span><br></pre></td></tr></table></figure><p>完蛋了，<code>修改了test文件的编码为utf-8</code>这一次最新版本的提交记录果然没了，而且我还没记住它的<code>commit id</code>，那怎么退回去？</p><p>你需要<code>git reflog</code>命令</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br><span class=line>3</span><br><span class=line>4</span><br><span class=line>5</span><br><span class=line>6</span><br><span class=line>7</span><br><span class=line>8</span><br><span class=line>9</span><br><span class=line>10</span><br><span class=line>11</span><br><span class=line>12</span><br><span class=line>13</span><br><span class=line>14</span><br></pre></td><td class=code><pre><span class=line>$ git reflog</span><br><span class=line>b94e156 (HEAD -&gt; master) HEAD@&#123;0&#125;: reset: moving to b94e15</span><br><span class=line>1cc9ea2 HEAD@&#123;1&#125;: commit: 修改了<span class=built_in>test</span>文件的编码为utf-8</span><br><span class=line>b94e156 (HEAD -&gt; master) HEAD@&#123;2&#125;: reset: moving to b94e156</span><br><span class=line>60e0866 HEAD@&#123;3&#125;: reset: moving to 60e08</span><br><span class=line>b94e156 (HEAD -&gt; master) HEAD@&#123;4&#125;: commit: 修改了readme文件并且添加了<span class=built_in>test</span>文件</span><br><span class=line>b50eaa6 HEAD@&#123;5&#125;: reset: moving to b50ea</span><br><span class=line>38448a2 HEAD@&#123;6&#125;: reset: moving to HEAD^^</span><br><span class=line>b50eaa6 HEAD@&#123;7&#125;: reset: moving to b50ea</span><br><span class=line>03b9408 HEAD@&#123;8&#125;: reset: moving to HEAD^</span><br><span class=line>b50eaa6 HEAD@&#123;9&#125;: commit: 第五次修改，增加了学习Git的说明</span><br><span class=line>03b9408 HEAD@&#123;10&#125;: commit: 第三次修改</span><br><span class=line>38448a2 HEAD@&#123;11&#125;: commit: 添加了分割线</span><br><span class=line>60e0866 HEAD@&#123;12&#125;: commit (initial): 第一次上传</span><br></pre></td></tr></table></figure><p>这里记录了你执行过的提交命令，ok，找到最新版本的<code>commit id</code>是<code>1cc9ea2</code>了，现在，我们又可以回到最新版了</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br><span class=line>2</span><br></pre></td><td class=code><pre><span class=line>$ git reset --hard 1cc9ea2</span><br><span class=line>HEAD is now at 1cc9ea2 修改了<span class=built_in>test</span>文件的编码为utf-8</span><br></pre></td></tr></table></figure><h3 id=管理修改><a href=#管理修改 class=headerlink title=管理修改></a>管理修改</h3><p>如果做如下操作，那么第二次的修改是不会被提交的</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br></pre></td><td class=code><pre><span class=line>第一次修改 -&gt; git add -&gt; 第二次修改 -&gt; git commit</span><br></pre></td></tr></table></figure><p><code>git add</code>后，做了其它修改，然后再提交也只会提交<code>git add</code>之前的修改，想把第二次修改提交还要再<code>git add</code>一次然后提交才行</p><p>例如：</p><figure class="highlight plain"><table><tr><td class=gutter><pre><span class=line>1</span><br></pre></td><td class=code><pre><span class=line>第一次修改 -&gt; git add -&gt;第二次修改 -&gt; git commit -&gt;git add -&gt;git commit</span><br></pre></td></tr></table></figure><p>或者</p><p>先不急着提交，第二次修改后再<code>git add</code>，然后提交，相当于把两次修改合并了一块儿提交</p><figure class="highlight bash"><table><tr><td class=gutter><pre><span class=line>1</span><br></pre></td><td class=code><pre><span class=line>第一次修改 -&gt; git add -&gt; 第二次修改 -&gt; git add -&gt;git commit</span><br></pre></td></tr></table></figure></div><div><ul class=post-copyright><li class=post-copyright-author><strong>本文作者：</strong>枫雨</li><li class=post-copyright-link><strong>本文链接：</strong> <a href=http://https://fyypll.gitee.io/note/posts/caff8000.html title=Git常用命令>http://https://fyypll.gitee.io/note/posts/caff8000.html</a></li><li class=post-copyright-license><strong>版权声明：</strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel=noopener target=_blank><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！</li></ul></div><footer class=post-footer><div class=post-tags><a href="/note/tags/Git/" <i class="fa fa-tag">Git</a></div><div class=post-nav><div class="post-nav-next post-nav-item"></div><span class=post-nav-divider></span><div class="post-nav-prev post-nav-item"><a href=/note/posts/1588fba0.html rel=prev title=Hexo踩坑记录>Hexo踩坑记录 <i class="fa fa-chevron-right"></i></a></div></div></footer></div></article></div></div><div class=comments id=comments></div></div><div class=sidebar-toggle><div class=sidebar-toggle-line-wrap><span class="sidebar-toggle-line sidebar-toggle-line-first"></span> <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span> <span class="sidebar-toggle-line sidebar-toggle-line-last"></span></div></div><aside id=sidebar class=sidebar><div class=sidebar-inner><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc sidebar-nav-active" data-target=post-toc-wrap>文章目录</li><li class=sidebar-nav-overview data-target=site-overview-wrap>站点概览</li></ul><div class="site-overview-wrap sidebar-panel"><div class=site-overview><div class="site-author motion-element" itemprop=author itemscope itemtype=http://schema.org/Person><a href="/about/"><img class=site-author-image itemprop=image src=/note/images/author.jpg alt=枫雨></a><p class=site-author-name itemprop=name>枫雨</p><div class="site-description motion-element" itemprop=description>时光再美，怎如初见</div></div><nav class="site-state motion-element"><div class="site-state-item site-state-posts"><a href="/note/archives/"><span class=site-state-item-count>13</span> <span class=site-state-item-name>日志</span></a></div><div class="site-state-item site-state-categories"><a href="/note/categories/"><span class=site-state-item-count>13</span> <span class=site-state-item-name>分类</span></a></div><div class="site-state-item site-state-tags"><a href="/note/tags/"><span class=site-state-item-count>17</span> <span class=site-state-item-name>标签</span></a></div></nav><div class="feed-link motion-element"><a href=/note/atom.xml rel=alternate><i class="fa fa-rss"></i> RSS</a></div><div class="links-of-author motion-element"><span class=links-of-author-item><a href=https://github.com/fyypll title="GitHub &rarr; https://github.com/fyypll" rel=noopener target=_blank><i class="fa fa-fw fa-github"></i>GitHub</a></span> <span class=links-of-author-item><a href=mailto:fyypll@163.com title="邮箱 &rarr; mailto:fyypll@163.com" rel=noopener target=_blank><i class="fa fa-fw fa-envelope"></i>邮箱</a></span> <span class=links-of-author-item><a href=https://weibo.com/3825907933 title="微博 &rarr; https://weibo.com/3825907933" rel=noopener target=_blank><i class="fa fa-fw fa-weibo"></i>微博</a></span> <span class=links-of-author-item><a href="http://wpa.qq.com/msgrd?v=3&uin=1451332278&site=qq&menu=yes" title="QQ &rarr; http://wpa.qq.com/msgrd?v=3&uin=1451332278&site=qq&menu=yes" rel=noopener target=_blank><i class="fa fa-fw fa-qq"></i>QQ</a></span></div><div class="links-of-blogroll motion-element links-of-blogroll-inline"><div class=links-of-blogroll-title><i class="fa fa-fw fa-link"></i> 友谊之门</div><ul class=links-of-blogroll-list><li class=links-of-blogroll-item><a href=http://rainss.cn title=http://rainss.cn rel=noopener target=_blank>雨落凋殇</a></li><li class=links-of-blogroll-item><a href=http://wanbk.net title=http://wanbk.net rel=noopener target=_blank>千寻博客</a></li><li class=links-of-blogroll-item><a href=http://www.sumushao.com title=http://www.sumushao.com rel=noopener target=_blank>苏木三少</a></li><li class=links-of-blogroll-item><a href=http://blog.bilili.me title=http://blog.bilili.me rel=noopener target=_blank>哔呖哩</a></li><li class=links-of-blogroll-item><a href=http://www.muruoxi.com title=http://www.muruoxi.com rel=noopener target=_blank>暮若夕</a></li></ul></div></div></div><div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active"><div class=post-toc><div class=post-toc-content><ol class=nav><li class="nav-item nav-level-3"><a class=nav-link href=#配置信息><span class=nav-number>1.</span> <span class=nav-text>配置信息</span></a></li><li class="nav-item nav-level-3"><a class=nav-link href=#创建仓库><span class=nav-number>2.</span> <span class=nav-text>创建仓库</span></a></li><li class="nav-item nav-level-3"><a class=nav-link href=#添加文件到仓库><span class=nav-number>3.</span> <span class=nav-text>添加文件到仓库</span></a></li><li class="nav-item nav-level-3"><a class=nav-link href=#查看仓库当前状态><span class=nav-number>4.</span> <span class=nav-text>查看仓库当前状态</span></a></li><li class="nav-item nav-level-3"><a class=nav-link href=#查看文件的改动情况><span class=nav-number>5.</span> <span class=nav-text>查看文件的改动情况</span></a></li><li class="nav-item nav-level-3"><a class=nav-link href=#查看改动历史记录><span class=nav-number>6.</span> <span class=nav-text>查看改动历史记录</span></a></li><li class="nav-item nav-level-3"><a class=nav-link href=#版本回退><span class=nav-number>7.</span> <span class=nav-text>版本回退</span></a></li><li class="nav-item nav-level-3"><a class=nav-link href=#管理修改><span class=nav-number>8.</span> <span class=nav-text>管理修改</span></a></li></ol></div></div></div><div class=back-to-top><i class="fa fa-arrow-up"></i> <span id=scrollpercent><span>0</span>%</span></div></div></aside></div></main><footer id=footer class=footer><div class=footer-inner><div class=copyright>&copy; <span itemprop=copyrightYear>2019</span> <span class=with-love id=animate><i class="fa fa-leaf"></i></span> <span class=author itemprop=copyrightHolder>枫雨</span> <span class=post-meta-divider>|</span> <span class=post-meta-item-icon><i class="fa fa-area-chart"></i></span> <span title=站点总字数>36k</span> <span class=post-meta-divider>|</span> <span class=post-meta-item-icon><i class="fa fa-coffee"></i></span> <span title=站点阅读时长>32 分钟</span></div><div class=busuanzi-count><script async src=https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js></script><span class=post-meta-item-icon><i class="fa fa-user"></i></span> <span class=site-uv title=总访客量><span class=busuanzi-value id=busuanzi_value_site_uv></span></span> <span class=post-meta-divider>|</span> <span class=post-meta-item-icon><i class="fa fa-eye"></i></span> <span class=site-pv title=总访问量><span class=busuanzi-value id=busuanzi_value_site_pv></span></span></div></div></footer></div><script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script><script src="/note/lib/jquery/index.js?v=2.1.3"></script><script src="/note/lib/velocity/velocity.min.js?v=1.2.1"></script><script src="/note/lib/velocity/velocity.ui.min.js?v=1.2.1"></script><script src="/note/js/utils.js?v=7.1.1"></script><script src="/note/js/motion.js?v=7.1.1"></script><script src="/note/js/affix.js?v=7.1.1"></script><script src="/note/js/schemes/pisces.js?v=7.1.1"></script><script src="/note/js/scrollspy.js?v=7.1.1"></script><script src="/note/js/post-details.js?v=7.1.1"></script><script src="/note/js/next-boot.js?v=7.1.1"></script><script src=//cdn1.lncld.net/static/js/3.11.1/av-min.js></script><script src=//unpkg.com/valine/dist/Valine.min.js></script><script>
  var GUEST = ['nick', 'mail', 'link'];
  var guest = 'nick,mail,link';
  guest = guest.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#comments',
    verify: false,
    notify: false,
    appId: 'vtQJiWDg4eWTEHmVI2JusGDk-gzGzoHsz',
    appKey: 'LOv8VuIVfV8I2qUO5DARavwe',
    placeholder: '你确定不留下些什么吗？',
    avatar: 'mm',
    meta: guest,
    pageSize: '10' || 10,
    visitor: false,
    lang: '' || 'zh-cn'
  });
</script><script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/note/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script></body></html>